﻿using AdminSystem.Applications;
using AdminSystem.Domain.User;
using AdminSystem.Repositories;
using AdminSystem.Write.API.Command.ShoppsCommand;
using MediatR;

namespace AdminSystem.Write.API.Handers.ShoppsHnader
{
    public class ShoppCommandHandler : IRequestHandler<ShoppCommand, ApiResult<List<Shopp>>>
    {
        public ShoppCommandHandler(IRepository<Shopp> ShoppRepository)
        {
            this.ShoppRepository = ShoppRepository;
        }

        public IRepository<Shopp> ShoppRepository { get; }
        /// <summary>
        /// 查询商品表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<List<Shopp>>> Handle(ShoppCommand request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<List<Shopp>> result = new ApiResult<List<Shopp>>();
                result.statusCode = StatusCode.Success;
                result.Message = "查询成功";
                var list = ShoppRepository.GetAll().Result.ToList();
                result.Data = list;
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
